package com.gang.util_demo.enumpackage;

import java.util.Objects;

public enum SexEnum {

    MAN(01, "男"),
    WOMEN(02, "女"),
    OTHER(03, "其他");

    int code;
    String name;

    SexEnum(int code, String name) {
        this.code = code;
        this.name = name;
    }

    SexEnum() {
    }

    /**
     * 根据编码获得性别枚举
     * @return
     */
    public static SexEnum getByCode(Integer code){
        for (SexEnum sexEnum : SexEnum.values()) {
            if (Objects.equals(sexEnum.getCode(), code)) {
                return sexEnum;
            }
        }
        return null;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}
